package com.fwixvye.controller;

import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class ScreenshotUpload {

    @PostMapping("/fileUploadTest")
    public String handleFileUpload(@RequestPart("file") MultipartFile file, @RequestPart("name")String name) throws IOException {
//         处理文件上传逻辑
        System.out.println(name);
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        file.transferTo(new File("D:\\下载"+UUID.randomUUID()+file.getOriginalFilename()));


        if (!file.isEmpty()) {
            // 保存文件或进行其他操作
            return "File uploaded successfully: " + file.getOriginalFilename();
        } else {
            return "Failed to upload file.";
        }
    }

}
